﻿Imports System.Data.SqlClient
Public Class frmChungTu
    Private strLoaiCT As String = ""
    Public booThanhCong As Boolean = False
    Sub New(Optional ByVal LoaiCT As String = "")

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        strLoaiCT = LoaiCT
    End Sub

    Private Sub frmChungTu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If strLoaiCT <> "" Then
            DocDuLieu(strLoaiCT)
        End If
    End Sub

    Private Sub btnLuu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLuu.Click
        If strLoaiCT <> "" Then

        End If
    End Sub

    Private Sub btnHuyBo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHuyBo.Click
        Me.Close()
    End Sub

    Private Function ThemMoiChungTu(ByVal LoaiCT As String, ByVal TenCT As String, ByVal GhiChu As String) As Boolean
        Dim strSql As String = "Select LoaiCT as [Mã chứng từ], TenCT as [Tên chứng từ], GhiChu as [Diễn giải] from ChungTu"
        Dim myConn As New SqlConnection(modKetNoi.strConnectionString)
        Dim myTable As New DataTable
        Try
            myConn.Open()
            Dim myAdapter As New SqlDataAdapter(strSql, myConn)
            myAdapter.Fill(myTable)

        Catch ex As Exception

        End Try
        myConn.Close()
        myConn.Dispose()
        Return True
    End Function

    Private Sub DocDuLieu(ByVal LoaiCT As String)
        Dim strSql As String = "Select * from ChungTu where LoaiCT = @LoaiCT"
        Dim myConn As New SqlConnection(modKetNoi.strConnectionString)
        Dim myTable As New DataTable
        Try
            myConn.Open()
            Dim myAdapter As New SqlDataAdapter(strSql, myConn)
            myAdapter.SelectCommand.Parameters.AddWithValue("@LoaiCT", LoaiCT)
            myAdapter.Fill(myTable)
            If myTable.Rows.Count > 0 Then
                Me.txtLoaiCT.Text = myTable.Rows(0).Item(0)
                Me.txtTenCT.Text = myTable.Rows(0).Item(1)
                Me.txtChiChu.Text = myTable.Rows(0).Item(2)
            End If
        Catch ex As Exception

        End Try
        myConn.Close()
        myConn.Dispose()
    End Sub
End Class